import axios from './../utils/http';

import $store from './../store';
class buyTicket {
  // 得到购票的状态，
  getTicketState(corpId, activityId) {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };
      // 注意
      // 去掉服务端数据时候，同步一下其他的
      // let resData = {
      //   "success": true,
      //   "errorMsg": null,
      //   "result": {
      //     "activityId": 1,
      //     "title": "UCAN设计大会",
      //     "address": "",
      //     "isEnable": 0,
      //     "startDate": 1550764800000,
      //     "enddate": 1551369599000,
      //     "corpId": "ding3693d292f695a58d35c2f4657eb6378f",
      //     "createDate": 1568996330000,
      //     "updateDate": 1550804841000,
      //     "startSaleDate": 1548999951000,
      //     "countdownDate": 1538999151000,
      //     // --
      //     // "createDate": 1548999890000,
      //     // "updateDate": 1550804841000,
      //     // "startSaleDate": 1548999951000,
      //     // "countdownDate": 1538999151000,
      //     "limitNum": 15,
      //     "connectEmail": "1123",
      //     "customerServiceTel": "13245678",
      //     "resources": null
      //   }
      // };
      // if (resData.success) {
      //   resolveData.success = true;
      //   resolveData.result = resData.result;
      //   $store.state.buyTicket.startSaleDate = resData.result.startSaleDate || 0; //开售时间
      //   $store.state.buyTicket.countdownDate = resData.result.countdownDate || 0; //倒计时时间
      //   $store.state.buyTicket.createDate = resData.result.createDate || 0 || new Date().getTime(); //当前时间
      //   $store.state.buyTicket.limitNum = Number(resData.result.limitNum) || 0; //限购数量
      //   if ($store.state.buyTicket.limitNum < 0) {
      //     $store.state.buyTicket.limitNum = 0;
      //   }
      //   $store.state.buyTicket.connectEmail = resData.result.connectEmail; //客服邮箱
      //   $store.state.buyTicket.customerServiceTel = resData.result.customerServiceTel; //客服电话
      //   //是否已开售,true已开售
      //   if ($store.state.buyTicket.startSaleDate < $store.state.buyTicket.createDate) {
      //     $store.state.buyTicket.noSale = true;
      //   } else {
      //     $store.state.buyTicket.noSale = false;
      //   }
      //   //是否显示倒计时 true 显示
      //   if ($store.state.buyTicket.countdownDate <= $store.state.buyTicket.createDate && $store.state.buyTicket.createDate < $store.state.buyTicket.startSaleDate) {
      //     $store.state.buyTicket.ifShowTimeDown = true;
      //   } else {
      //     $store.state.buyTicket.ifShowTimeDown = false;
      //   }

      //   // 剩余时间 开售时间-当前时间=剩余时间的毫秒数
      //   let nowDate = $store.state.buyTicket.createDate;
      //   let endDate = $store.state.buyTicket.startSaleDate;
      //   $store.state.buyTicket.surplusData =
      //     ((Number(endDate) || 0) - (Number(nowDate) || 0)) / 1000; //多少秒
      //   // $store.state.buyTicket.noSale = false; //为了测试
      //   // $store.state.buyTicket.limitNum = 8; //为了测试
      // } else {
      //   resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
      // }
      // resolve(resolveData);
      // return;
      let subData = {
        corpId: corpId,
        activityId: activityId,
      };
      axios.post('ticketPurchaseMob/queryActivityById',
        subData,
      ).then(resData => {
        if (resData.success) {
          resolveData.success = true;
          resolveData.result = resData.result;
          $store.state.buyTicket.startSaleDate = resData.result.startSaleDate || 0; //开售时间
          $store.state.buyTicket.countdownDate = resData.result.countdownDate || 0; //倒计时时间
          $store.state.buyTicket.createDate = resData.result.createDate || 0 || new Date().getTime(); //当前时间
          $store.state.buyTicket.limitNum = Number(resData.result.limitNum) || 0; //限购数量
          if ($store.state.buyTicket.limitNum < 0) {
            $store.state.buyTicket.limitNum = 0;
          }
          $store.state.buyTicket.connectEmail = resData.result.connectEmail; //客服邮箱
          $store.state.buyTicket.customerServiceTel = resData.result.customerServiceTel; //客服电话
          //是否已开售,true已开售
          if ($store.state.buyTicket.startSaleDate < $store.state.buyTicket.createDate) {
            $store.state.buyTicket.noSale = true;
          } else {
            $store.state.buyTicket.noSale = false;
          }
          //是否显示倒计时 true 显示
          if ($store.state.buyTicket.countdownDate <= $store.state.buyTicket.createDate && $store.state.buyTicket.createDate < $store.state.buyTicket.startSaleDate) {
            $store.state.buyTicket.ifShowTimeDown = true;
          } else {
            $store.state.buyTicket.ifShowTimeDown = false;
          }

          // 剩余时间 开售时间-当前时间=剩余时间的毫秒数
          let nowDate = $store.state.buyTicket.createDate;
          let endDate = $store.state.buyTicket.startSaleDate;
          $store.state.buyTicket.surplusData =
            ((Number(endDate) || 0) - (Number(nowDate) || 0)) / 1000; //多少秒
          // $store.state.buyTicket.noSale = false; //为了测试
          // $store.state.buyTicket.limitNum = 8; //为了测试
        } else {
          resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
        }
        resolve(resolveData);
      }, err => {
        resolveData.errorMsg = '服务器出小差了！';
        resolve(resolveData);
      });
    });
  }
  // 得到门票基础数据
  getTicketList(linkId) {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };
      // 注意
      // 去掉服务端数据时候，同步一下其他的
      // let resData = {
      //   "success": true,
      //   "errorMsg": null,
      //   "result": {
      //     "head": {
      //       "pricegroupId": 17,
      //       "projectId": 1,
      //       "ptype": 0,
      //       "status": 0,
      //       "pname": "ucan大会",
      //       "vnote": null,
      //       "updateTime": 1551280739000,
      //       "createTime": 1551077277000,
      //       "isDel": 0
      //     },
      //     "corpId": "ding3693d292f695a58d35c2f4657eb6378f",
      //     "body": [{
      //       "pricegroupbId": 39,
      //       "pricegroupId": 17,
      //       "ticketId": 15,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551256393000,
      //       "createTime": 1551077277000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 159,
      //       "snum": 41,
      //       "eprice": 0.02,
      //       "sprice": 0.02,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "早鸟票m",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-18:00",
      //       "ticketUrl": "https://static.dingtalk.com/media/lADPDeC2t5YcjAvOADUAaM4AeQAt_7929901_3473512.jpg"
      //     }, {
      //       "pricegroupbId": 40,
      //       "pricegroupId": 17,
      //       "ticketId": 16,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551269647000,
      //       "createTime": 1551077277000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": -38,
      //       "snum": 39,
      //       "eprice": 0.01,
      //       "sprice": 0.01,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "正常票",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-18:00",
      //       "ticketUrl": "https://static.dingtalk.com/media/lADPDeC2t5YeSc3OAGkAdM4AYQB6_6357114_6881396.jpg"
      //     }, {
      //       "pricegroupbId": 41,
      //       "pricegroupId": 17,
      //       "ticketId": 18,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551088616000,
      //       "createTime": 1551077277000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": -2,
      //       "snum": 2,
      //       "eprice": 0.01,
      //       "sprice": 0.05,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "早鸟票2",
      //       "detail": "[\"地方\"]",
      //       "address": "二分我的",
      //       "stime": 1551196800000,
      //       "etime": 1551283200000,
      //       "tTypeDate": "09:00-09:17",
      //       "ticketUrl": "https://static.dingtalk.com/media/lADPDeC2t5bmANHNAXfNAfQ_500_375.jpg"
      //     }, {
      //       "pricegroupbId": 42,
      //       "pricegroupId": 17,
      //       "ticketId": 21,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551273608000,
      //       "createTime": 1551096706000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": 0,
      //       "eprice": null,
      //       "sprice": 1200.0,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "早鸟票",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛及6场工作坊任选2场\",\"展会免费进，互动装饰尽情玩\",\"免费获得精美UCAN礼包一份 \",\"可预约参加Design-Party嘉年华，有的玩，有交流\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-18:00",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDgQ9qg1IuhDNAUDNAQQ_260_320.png"
      //     }, {
      //       "pricegroupbId": 43,
      //       "pricegroupId": 17,
      //       "ticketId": 22,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": null,
      //       "createTime": 1551097113000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": 0,
      //       "eprice": null,
      //       "sprice": 1200.0,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "普通票",
      //       "detail": "[\" 主会场直面大咖\",\"9大分论坛任意选\",\"展会免费进，互动装饰尽情玩\",\"免费获得精美UCAN礼包一份\",\"可预约参加Design-Party 嘉年华，有的玩、有交流\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-18:00",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDgQ9qg1HGYrNAUDNAQQ_260_320.png"
      //     }, {
      //       "pricegroupbId": 49,
      //       "pricegroupId": 17,
      //       "ticketId": 23,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": null,
      //       "createTime": 1551100824000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": 0,
      //       "eprice": null,
      //       "sprice": 0.01,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "测试票",
      //       "detail": "[\"aa\"]",
      //       "address": "111",
      //       "stime": 1551024000000,
      //       "etime": 1551283200000,
      //       "tTypeDate": "09:05-09:12",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDgQ9qgh7UlDNAU3NAaI_418_333.png"
      //     }, {
      //       "pricegroupbId": 51,
      //       "pricegroupId": 17,
      //       "ticketId": 25,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551256406000,
      //       "createTime": 1551160172000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": 0,
      //       "eprice": 0.01,
      //       "sprice": 0.02,
      //       "ableNum": null,
      //       "frozenNum": 0,
      //       "tname": "测试我的门票修改5555",
      //       "detail": "[\"11\"]",
      //       "address": "测试地址",
      //       "stime": 1551283200000,
      //       "etime": 1552320000000,
      //       "tTypeDate": "09:01-09:04",
      //       "ticketUrl": "https://static.dingtalk.com/media/lADPDeC2t5n7C6_OAGwAZM4ALgB0_3014772_7077988.jpg"
      //     }, {
      //       "pricegroupbId": 53,
      //       "pricegroupId": 17,
      //       "ticketId": 26,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551248391000,
      //       "createTime": 1551160883000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": "此处是折扣标签",
      //       "snote": "此处是价格标签",
      //       "inum": 0,
      //       "snum": 35,
      //       "eprice": 0.01,
      //       "sprice": 0.05,
      //       "ableNum": null,
      //       "frozenNum": 35,
      //       "tname": "早鸟票",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-10:10",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDeC2t5n7wUDOADUAaM4AeQAt_7929901_3473512.png"
      //     }, {
      //       "pricegroupbId": 55,
      //       "pricegroupId": 17,
      //       "ticketId": 27,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551256890000,
      //       "createTime": 1551161061000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": "此处是折扣标签",
      //       "snote": "此处是价格标签",
      //       "inum": -10,
      //       "snum": 30,
      //       "eprice": 0.01,
      //       "sprice": 0.01,
      //       "ableNum": null,
      //       "frozenNum": 40,
      //       "tname": "正常票",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-09:41",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDeC2t5oFsjHOBQAAAM0FAQ_1281_83886080.png"
      //     }, {
      //       "pricegroupbId": 60,
      //       "pricegroupId": 17,
      //       "ticketId": 29,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": null,
      //       "createTime": 1551253741000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": null,
      //       "eprice": null,
      //       "sprice": 0.05,
      //       "ableNum": null,
      //       "frozenNum": null,
      //       "tname": "早鸟票新库存充足",
      //       "detail": "[\"权益\"]",
      //       "address": "地址",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-09:37",
      //       "ticketUrl": "https://static.dingtalk.com/media/lADPDeC2t5zODejOADUAaM4AeQAt_7929901_3473512.jpg"
      //     }, {
      //       "pricegroupbId": 63,
      //       "pricegroupId": 17,
      //       "ticketId": 30,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": null,
      //       "createTime": 1551254218000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": null,
      //       "eprice": null,
      //       "sprice": 0.01,
      //       "ableNum": null,
      //       "frozenNum": null,
      //       "tname": "早鸟票",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1551283200000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-18:00",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDgQ9qgyUB5TMoMyC_130_160.png"
      //     }, {
      //       "pricegroupbId": 66,
      //       "pricegroupId": 17,
      //       "ticketId": 31,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551279368000,
      //       "createTime": 1551255106000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": "此处是折扣标签",
      //       "snote": "此处是价格标签",
      //       "inum": -177390,
      //       "snum": 11,
      //       "eprice": 0.01,
      //       "sprice": 0.05,
      //       "ableNum": null,
      //       "frozenNum": 177529,
      //       "tname": "早鸟票头图新",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "此处是地址",
      //       "stime": 1551110400000,
      //       "etime": 1551283200000,
      //       "tTypeDate": "09:00-10:10",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDeC2t5zhienOADkAY84AMABh_3145825_3735651.png"
      //     }, {
      //       "pricegroupbId": 69,
      //       "pricegroupId": 17,
      //       "ticketId": 32,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551277597000,
      //       "createTime": 1551255193000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": -21,
      //       "snum": 8,
      //       "eprice": 0.01,
      //       "sprice": 0.01,
      //       "ableNum": null,
      //       "frozenNum": 22,
      //       "tname": "正常票头图新",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "地址",
      //       "stime": 1550678400000,
      //       "etime": 1551283200000,
      //       "tTypeDate": "09:00-09:37",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDeC2t5zip8DOAGkAdM4AYQB6_6357114_6881396.png"
      //     }, {
      //       "pricegroupbId": 72,
      //       "pricegroupId": 17,
      //       "ticketId": 33,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": null,
      //       "createTime": 1551277851000,
      //       "isDel": 0,
      //       "status": 1,
      //       "enote": null,
      //       "snote": null,
      //       "inum": 0,
      //       "snum": null,
      //       "eprice": null,
      //       "sprice": 0.01,
      //       "ableNum": null,
      //       "frozenNum": null,
      //       "tname": "正常票汇",
      //       "detail": "[\"权益\"]",
      //       "address": "此处是地址",
      //       "stime": 1549468800000,
      //       "etime": 1552492800000,
      //       "tTypeDate": "09:00-09:28",
      //       "ticketUrl": "https://static.dingtalk.com/media/lADPDeC2t520DZ7OAGkAdM4AYQB6_6357114_6881396.jpg"
      //     }, {
      //       "pricegroupbId": 75,
      //       "pricegroupId": 17,
      //       "ticketId": 34,
      //       "exclusive": null,
      //       "vnote": null,
      //       "updateTime": 1551280833000,
      //       "createTime": 1551280723000,
      //       "isDel": 0,
      //       "status": 0,
      //       "enote": "此处是折扣标签",
      //       "snote": "此处是价格标签",
      //       "inum": 100,
      //       "snum": null,
      //       "eprice": 0.01,
      //       "sprice": 0.05,
      //       "ableNum": null,
      //       "frozenNum": null,
      //       "tname": "早鸟票",
      //       "detail": "[\"主会场直面大咖\",\"9大主题分论坛\",\"设计作品展，互动装饰尽情玩\",\"参加Design-party嘉年华，有的玩，有交流\",\"可免费进入展会区域\",\"精美礼包一份\"]",
      //       "address": "杭州国际博览中心",
      //       "stime": 1556294400000,
      //       "etime": 1556380800000,
      //       "tTypeDate": "09:00-10:26",
      //       "ticketUrl": "https://static.dingtalk.com/media/lALPDeC2t529nkPOAGkAdM4AYQB6_6357114_6881396.png"
      //     }],
      //     "agereeId": "[2]"
      //   }
      // }

      // if (resData.success) {
      //   if (resData.result.length !== 0) {
      //     resolveData.success = true;
      //     let dataArrOld = [resData.result];
      //     let dataArr = [];
      //     for (let i = 0; i < dataArrOld.length; i++) {
      //       let obj = dataArrOld[i];
      //       let body = JSON.parse(JSON.stringify(obj.body));
      //       let arr = [];
      //       for (let j = 0; j < body.length; j++) {
      //         if (body[j].status === 0) {
      //           arr.push(body[j]);
      //         }
      //       }
      //       obj.body = arr;
      //       dataArr.push(obj);
      //     }
      //     let inumSum = 0; //库存总量
      //     let snumSum = 0; //销售总量
      //     for (let i = 0; i < dataArr.length; i++) {


      //       // 复制且存储防止其它页面刷新数据丢失
      //       $store.state.buyTicket.activityId = dataArr[i].head.projectId; //活动ID 
      //       sessionStorage.setItem('activityIdUcan', $store.state.buyTicket.activityId);

      //       // $store.state.buyTicket.ticketTypeId = dataArr[i].head.pricegroupId; //票类型id
      //       // sessionStorage.setItem('ticketTypeIdUcan', $store.state.buyTicket.ticketTypeId);

      //       if (typeof dataArr[i].agereeId == 'string') {
      //         $store.state.buyTicket.agereeId = dataArr[i].agereeId.split(",")[0]; //《购票服务协议》
      //       } else {
      //         $store.state.buyTicket.agereeId = JSON.parse(dataArr[i].agereeId)[0]; //《购票服务协议》
      //       }
      //       sessionStorage.setItem('agereeIdUcan', $store.state.buyTicket.agereeId);

      //       $store.state.buyTicket.corpId = dataArr[i].corpId; //组织corpId,
      //       sessionStorage.setItem('corpIdUcan', $store.state.buyTicket.corpId);



      //       for (let j = 0; j < dataArr[i].body.length; j++) {

      //         // 写死默认多张票都对应一张表单
      //         if (!$store.state.buyTicket.ticketTypeId) {
      //           $store.state.buyTicket.ticketTypeId = dataArr[i].body[j].ticketId; //票id
      //           sessionStorage.setItem('ticketTypeIdUcan', $store.state.buyTicket.ticketTypeId);
      //         }


      //         // 如果没有原价，则赋值0
      //         if (!dataArr[i].body[j].sprice) {
      //           dataArr[i].body[j].sprice = 0;
      //         }
      //         // 处理没有且非0折扣价格的时候，折扣价就是原价
      //         if (dataArr[i].body[j].eprice === null || dataArr[i].body[j].eprice === '') {
      //           dataArr[i].body[j].eprice = dataArr[i].body[j].sprice;
      //         }
      //         if (Number(dataArr[i].body[j].inum) >= 0) {
      //           inumSum += Number(dataArr[i].body[j].inum) || 0;
      //         }
      //         snumSum += Number(dataArr[i].body[j].snum) || 0;
      //       }
      //     }
      //     // 判断是否已经已售罄
      //     if (inumSum <= 0) {
      //       $store.state.buyTicket.soldOut = true;
      //     } else {
      //       $store.state.buyTicket.soldOut = false;
      //     }
      //     // $store.state.buyTicket.soldOut = true; //为了测试
      //     resolveData.result = dataArr;
      //     $store.state.buyTicket.ticketList = resolveData.result;
      //     sessionStorage.setItem('ticketListUcan', JSON.stringify($store.state.buyTicket.ticketList));
      //   } else {
      //     resolveData.errorMsg = '未获取到相关数据';
      //   }
      // } else {
      //   resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
      // }
      // resolve(resolveData);
      // return;
      axios.get('ticketPurchaseMob/queryTicketInfoList?linkId=' + linkId).then(resData => {
        if (resData.success) {
          if (resData.result.length !== 0) {
            resolveData.success = true;
            let dataArrOld = [resData.result];
            let dataArr = [];
            for (let i = 0; i < dataArrOld.length; i++) {
              let obj = dataArrOld[i];
              let body = JSON.parse(JSON.stringify(obj.body));
              let arr = [];
              for (let j = 0; j < body.length; j++) {
                if (body[j].status === 0) {
                  arr.push(body[j]);
                }
              }
              obj.body = arr;
              dataArr.push(obj);
            }
            let inumSum = 0; //库存总量
            let snumSum = 0; //销售总量
            for (let i = 0; i < dataArr.length; i++) {


              // 复制且存储防止其它页面刷新数据丢失
              $store.state.buyTicket.activityId = dataArr[i].head.projectId; //活动ID 
              sessionStorage.setItem('activityIdUcan', $store.state.buyTicket.activityId);

              // $store.state.buyTicket.ticketTypeId = dataArr[i].head.pricegroupId; //票类型id
              // sessionStorage.setItem('ticketTypeIdUcan', $store.state.buyTicket.ticketTypeId);

              if (typeof dataArr[i].agereeId == 'string') {
                $store.state.buyTicket.agereeId = dataArr[i].agereeId.split(",")[0]; //《购票服务协议》
              } else {
                $store.state.buyTicket.agereeId = JSON.parse(dataArr[i].agereeId)[0]; //《购票服务协议》
              }
              sessionStorage.setItem('agereeIdUcan', $store.state.buyTicket.agereeId);

              $store.state.buyTicket.corpId = dataArr[i].corpId; //组织corpId,
              sessionStorage.setItem('corpIdUcan', $store.state.buyTicket.corpId);



              for (let j = 0; j < dataArr[i].body.length; j++) {

                // 写死默认多张票都对应一张表单
                if (!$store.state.buyTicket.ticketTypeId) {
                  $store.state.buyTicket.ticketTypeId = dataArr[i].body[j].ticketId; //票id
                  sessionStorage.setItem('ticketTypeIdUcan', $store.state.buyTicket.ticketTypeId);
                }


                // 如果没有原价，则赋值0
                if (!dataArr[i].body[j].sprice) {
                  dataArr[i].body[j].sprice = 0;
                }
                // 处理没有且非0折扣价格的时候，折扣价就是原价
                if (dataArr[i].body[j].eprice === null || dataArr[i].body[j].eprice === '') {
                  dataArr[i].body[j].eprice = dataArr[i].body[j].sprice;
                }
                if (Number(dataArr[i].body[j].inum) >= 0) {
                  inumSum += Number(dataArr[i].body[j].inum) || 0;
                }
                snumSum += Number(dataArr[i].body[j].snum) || 0;
              }
            }
            // 判断是否已经已售罄
            if (inumSum <= 0) {
              $store.state.buyTicket.soldOut = true;
            } else {
              $store.state.buyTicket.soldOut = false;
            }
            // $store.state.buyTicket.soldOut = true; //为了测试
            resolveData.result = dataArr;
            $store.state.buyTicket.ticketList = resolveData.result;
            sessionStorage.setItem('ticketListUcan', JSON.stringify($store.state.buyTicket.ticketList));
          } else {
            resolveData.errorMsg = '未获取到相关数据';
          }
        } else {
          resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
        }
        resolve(resolveData);
      }, err => {
        resolveData.errorMsg = '服务器出小差了！';
        resolve(resolveData);
      });
    });
  }
  //购票页用户预约开售提醒接口
  // countryCode:国家区号 mobile:手机号 activityId:项目主键
  reminderSale(countryCode, mobile, activityId) {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };
      let subData = {
        countryCode: countryCode,
        mobile: mobile,
        projectId: activityId
      };
      axios.post('ticket/saleRemind/subscribe', subData).then(
        resData => {
          if (resData.success) {
            resolveData.success = true;
            resolveData.result = resData.result;
          } else {
            resolveData.errorMsg = resData.errorMsg || '请重试';
          }
          resolve(resolveData);
        },
        err => {
          resolveData.errorMsg = '服务器出小差了！';
          resolve(resolveData);
        }
      );
    });
  };
  // 得到《购票服务协议》链接接口
  getAgeree(corpId, agereeId) {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };
      let subData = `?corpId=${corpId}&agereeId=${agereeId}`;
      axios.get('signUp/queryAgreeUrl' + subData).then(resData => {
        if (resData.success) {
          resolveData.success = true;
          resolveData.result = resData.result;
        } else {
          resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
        }
        resolve(resolveData);
      }, err => {
        resolveData.errorMsg = '服务器出小差了！';
        resolve(resolveData);
      });
    });
  };
  // 同意并付款生成订单
  checkPay(carTicketList) {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };
      let subData = {};
      if ($store.state.buyTicket.ticketList.length !== 0) {
        subData.head = $store.state.buyTicket.ticketList[0].head;
      } else {
        let ticketList = JSON.parse(sessionStorage.getItem('ticketListUcan')) || [];
        subData.head = ticketList[0].head;
      }
      let body_ticket = [];
      for (let i = 0; i < carTicketList.length; i++) {
        let obj = {
          'ticketId': carTicketList[i].body_ticket[0].ticketId,
          'pricegroupbId': carTicketList[i].body_ticket[0].pricegroupbId,
          'pricegroupId': carTicketList[i].body_ticket[0].pricegroupId,
          'num': carTicketList[i].body_ticket.length,
          'price': carTicketList[i].body_ticket[0].eprice,
          'mny': (Number(carTicketList[i].body_ticket[0].eprice) * carTicketList[i].body_ticket.length).toFixed(2),
          'ticket_psn': [],
        };
        for (let j = 0; j < carTicketList[i].useTicketPople.length; j++) {
          obj.ticket_psn.push({
            id: carTicketList[i].useTicketPople[j].userData.id
          });
        }
        body_ticket.push(obj);
      }
      subData.body_ticket = body_ticket;
      axios.post('ticketPurchaseMob/addTicketOrder', subData).then(
        resData => {
          if (resData.success) {
            resolveData.success = true;
            resolveData.result = resData.result;
          } else {
            resolveData.errorMsg = resData.errorMsg || '请重试';
          }
          resolve(resolveData);
        },
        err => {
          resolveData.errorMsg = '服务器出小差了！';
          resolve(resolveData);
        }
      );
    });
  };
  // 得到购物车中的票列表数据
  getCarTicketList() {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };

      //没有购物车暂存的。默认查出空
      resolveData.success = true;
      resolveData.result = [];
      $store.state.buyTicket.carTicketList = resolveData.result;

      // 进行数据拆分，一共有多少张票
      $store.state.buyTicket.carTicketSumList = [];
      let carTicketList = $store.state.buyTicket.carTicketList;
      for (let i = 0; i < carTicketList.length; i++) {
        for (let j = 0; j < carTicketList[i].body_ticket.length; j++) {
          $store.state.buyTicket.carTicketSumList.push(
            carTicketList[i].body_ticket[j]
          );
        }
      }
      resolve(resolveData);
      // axios.get('ticketPurchaseMob/queryTicketOrderByPsnId').then(resData => {
      //   if (resData.success) {
      //     resolveData.success = true;
      //     resolveData.result = resData.result;
      //     $store.state.buyTicket.carTicketList = resolveData.result;

      //     // 进行数据拆分，一共有多少张票
      //     $store.state.buyTicket.carTicketSumList = [];
      //     let carTicketList = $store.state.buyTicket.carTicketList;
      //     for (let i = 0; i < carTicketList.length; i++) {
      //       for (let j = 0; j < carTicketList[i].body_ticket.length; j++) {
      //         $store.state.buyTicket.carTicketSumList.push(
      //           carTicketList[i].body_ticket[j]
      //         );
      //       }
      //     }
      //     // console.log($store.state.buyTicket.carTicketSumList);
      //   } else {
      //     resolveData.errorMsg = resData.errorMsg || '请重试';
      //   }
      //   resolve(resolveData);
      // }, err => {
      //   resolveData.errorMsg = '服务器出小差了！';
      //   resolve(resolveData);
      // });
    });
  }
  // 更新数据到购物车添加到服务器保存
  upDataCarTicketService(ticket) {
    return new Promise((resolve) => {
      let resolveData = {
        success: false,
        errorMsg: '',
        result: []
      };
      axios.post('ticketPurchaseMob/updateTicketOrder', ticket).then(resData => {
        if (resData.success) {
          resolveData.success = true;
          resolveData.result = resData.result;
        } else {
          resolveData.errorMsg = resData.errorMsg || '请重试';
        }
        resolve(resolveData);
      }, err => {
        resolveData.errorMsg = '服务器出小差了！';
        resolve(resolveData);
      });
    });
  }
}

export default new buyTicket();
